<template>
  <div class="commentItem" v-if="obj.parent">
    <div class="top">
      <div class="left">
        <span>{{ obj.parent.user.nickname }}</span> &nbsp;&nbsp;&nbsp;
        <span>2分钟前</span>
      </div>
      <span @click="reqlyFn(obj.id)">回复</span>
    </div>
    
    <!-- 组件调用自己 方法叫递归 -->
    <commentItem @sendData='reqlyFn' v-if="obj.parent" :obj="obj.parent"></commentItem>

    <div class="bottom">{{ obj.parent.content }}</div>
  </div>
</template>

<script>
export default {
    name:'commentItem',
  props: {
    obj: {
      type: Object,
      required: true,
    },
  },
  methods:{
      reqlyFn(id){
        //   子传父 把id传给父组件
          this.$emit('sendData',id)
      }
  }
};
</script>

<style lang="less" scoped>
.commentItem {
  border: 1px solid #ccc;
  padding: 5px;
  margin-top: 10px;
  .top {
    font-size: 12px;
    color: #aaa;
    display: flex;
    justify-content: space-between;
  }
  .bottom {
    font-size: 13px;
    line-height: 40px;
  }
}
</style>